var t = require('../@babel/runtime/helpers/typeof');
var app = getApp();

function a(t) {
    return '' === t || '{}' === JSON.stringify(t) || 'NAN' == t || 0 == t || null == t || 'null' == t || null == t || 'undefined' === t || 'undefined' == t;
}

function n(t) {
    return !!/^[0-9]*[1-9][0-9]*$/.test(t);
}

function i(t, e) {
    if (a(e)) {
        return '';
    }
    for (var n = e.length, i = [], r = 0; r < n; r++) {
        if (e[r].f == t) {
            i.push(e[r]);
        }
    }
    return i;
}

function r(t, e) {
    if ('string' == typeof t || 'number' == typeof t) {
        for (var a in e) {
            if (e[a] == t) {
                return true;
            }
        }
    }
    return false;
}

function o(t, e) {
    if (a(e)) {
        return '';
    }
    for (var n = 0; n < e.length; n++) {
        if (e[n].i == t) {
            return e[n].v;
        }
    }
}

module.exports = {
    set_options_aid: function (t, i) {
        var r;
        if (a(i)) {
            r = 0;
            i = {};
        } else {
            r = n(i.aid) ? i.aid : 0;
        }
        if (!n(r)) {
            for (var o = decodeURIComponent(i.scene), s = {}, c = 0; c < o.split('*').length; c++) {
                var l = o.split('*')[c].split('/');
                s[l[0]] = l[1];
            }
            r = n(s.aid) ? s.aid : 0;
        }
        var u = n(r) ? r : 0;
        app.globalData.aid = u;
        t.setData({
            aid: u
        });
        return u;
    },
    set_tabbar: function () {
        uni.setTabBarStyle({
            selectedColor: app.globalData._ZEAI.color,
            borderStyle: 'white'
        });
        var t = app.globalData._ZEAI.tabbar.length;
        if (t > 0) {
            for (var a = 0; a < t; a++) {
                uni.setTabBarItem({
                    index: a,
                    text: app.globalData._ZEAI.tabbar[a].text,
                    iconPath: app.globalData._ZEAI.tabbar[a].iconPath,
                    selectedIconPath: app.globalData._ZEAI.tabbar[a].selectedIconPath
                });
            }
        }
    },
    c16_rgb: function (t = '#8316d7') {
        if ("" === t) return "";
        t = t.substring(1).toLowerCase();
        var e;
        var a = new Array();
        for (e = 0; e < 3; e++) {
            a[0] = t.substr(2 * e, 2);
            a[3] = '0123456789abcdef';
            a[1] = a[0].substr(0, 1);
            a[2] = a[0].substr(1, 1);
            a[20 + e] = 16 * a[3].indexOf(a[1]) + a[3].indexOf(a[2]);
        }
        return a[20] + ',' + a[21] + ',' + a[22];
    },
    empty: a,
    ifmob: function (t) {
        return !!/^1[3,4,5,6,7,8,9]\d{9}$/.test(t);
    },
    ifsfz: function (t) {
        return false !== /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(t);
    },
    copy_text: function (t) {
        var e = a(t.msg) ? '复制成功' : t.msg;
        uni.setClipboardData({
            data: t.data,
            success: function (t) {
                uni.showToast({
                    title: e,
                    icon: 'success',
                    duration: 2000
                });
            }
        });
    },
    o: function (t, e) {
        var a = uni.createSelectorQuery();
        a.select(t).boundingClientRect();
        a.exec(function (t) {
            e(t);
        });
    },
    ifint: n,
    jsoneval: function (e) {
        return 'object' != t(e) ? ((e = e.replace(/\ufeff/g, '')), JSON.parse(e)) : e;
    },
    json_arr: function (t) {
        var e = [];
        for (var a in t) {
            var n = {};
            n[a] = t[a];
            e.push(n);
        }
        return e;
    },
    areaNEW: i,
    areaGetTtitle: function (t, e) {
        var n = t.length;
        var r = e.ARR1;
        var o = e.ARR2;
        var s = e.ARR3;
        var c = e.ARR4;
        var l = [];
        var u = [];
        var f = [];
        if (n >= 1) {
            var d = r[t[0]].i;
            var v = r[t[0]].v;
        }
        if (n >= 2) {
            var _ = i(d, o);
            if (!a(_)) {
                var p = _[t[1]].i;
                var b = _[t[1]].v;
            }
        }
        if (n >= 3) {
            var g = i(p, s);
            if (!a(g)) {
                var h = g[t[2]].i;
                var m = g[t[2]].v;
            }
        }
        if (n >= 4) {
            var k = i(h, c);
            if (!a(k)) {
                var x = k[t[3]].i;
                var w = k[t[3]].v;
            }
        }
        a(d) || (l.push(d), u.push(v));
        a(p) || (l.push(p), u.push(b));
        a(h) || (l.push(h), u.push(m));
        a(x) || (l.push(x), u.push(w));
        l = l.join(',');
        u = u.join(' ');
        f.push(l);
        f.push(u);
        return f;
    },
    in_array: r,
    set_checked: function (e, a) {
        for (var n = 'object' == t(e) ? e : e.split(','), i = 0; i < a.length; i++) {
            r(a[i].i, n) ? (a[i].ed = true) : (a[i].ed = false);
        }
        return a;
    },
    checkbox_div_list_get_listTitle: function (e, n) {
        if (a(e) || a(n)) {
            return '';
        }
        for (var i = 'object' != t(e) ? e.split(',') : e, r = [], s = 0; s < i.length; s++) {
            r.push(o(i[s], n));
        }
        return r.join(',');
    },
    idx_iv: function (e, n) {
        if (a(e) || a(n)) {
            return '';
        }
        var i;
        var r = 'object' != t(e) ? e.split(',') : e;
        var o = r.length;
        var s = (n.length, []);
        var c = [];
        var l = [];
        if (o > 1) {
            for (var u = 0; u < o; u++) {
                i = r[u];
                s.push(n[i].i);
                c.push(n[i].v);
            }
            l.push(s.join(','), c.join('～'));
        } else {
            l.push(n[e].i, n[e].v);
        }
        return l;
    },
    sorry: function (t) {
        var e = t.this;
        switch (t.flag) {
            case 'noreg':
                uni.navigateTo({
                    url: '/pages/login/login?tguid=' + t.tguid + '&admid=' + t.admid
                });
                break;
            case 'tg_noreg':
                uni.redirectTo({
                    url: '/hnPages/tg/login?tguid=' + t.tguid + '&admid=' + t.admid
                });
                break;
            case 'nosign':
                uni.showModal({
                    content: t.title,
                    confirmColor: e.color,
                    confirmText: '朕知道了',
                    showCancel: false,
                    success: function (t) {
                        uni.navigateBack();
                    }
                });
                break;
            case 'nodata':
                e.setData({
                    div_data: true,
                    div_data_title: t.title,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'nocontact':
                break;
            case 'nogps':
                e.setData({
                    div_gps: true,
                    div_gps_title: t.title,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'nolevel':
                e.setData({
                    div_vip: true,
                    div_vip_title: t.title,
                    div_vip_content: t.content,
                    div_vip_H: t.H,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'nocert':
                e.setData({
                    div_cert: true,
                    div_cert_title: t.title,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'nophoto':
                e.setData({
                    div_data: true,
                    div_data_title: t.title,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'clickloveb_confirm':
                e.setData({
                    div_clickloveb_confirm: true,
                    div_data_title: t.title,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'noloveb':
                e.setData({
                    div_noloveb: true,
                    div_data_title: t.title,
                    div_data_content: t.content,
                    mask_class: 'alpha0_100'
                });
                break;
            case 'noucount':
                e.setData({
                    div_noucount: true,
                    div_data_title: t.title,
                    mask_class: 'alpha0_100'
                });
                break;
            default:
                uni.showModal({
                    content: t.msg,
                    confirmColor: e.color,
                    confirmText: '朕知道了',
                    showCancel: false,
                    success: function (e) {
                        'no' == t.url || uni.navigateBack();
                    }
                });
        }
    },
    get_F_idx: function (t, e) {
        if (a(t) || a(e)) {
            return 0;
        }
        var n = e.length;
        if (n > 0) {
            for (var i = 0; i < n; i++) {
                if (e[i].fieldname == t) {
                    return i;
                }
            }
        }
    },
    escape2Html: function (t) {
        var e = {
            lt: '<',
            gt: '>',
            nbsp: ' ',
            amp: '&',
            quot: '"'
        };
        return (t = (t = t
            .replace(/&(lt|gt|nbsp|amp|quot);/gi, function (t, a) {
                return e[a];
            })
            .replace('<section', '<div')).replace(/<img/gi, '<img style="width:100%;height:auto;display:block" '));
    },
    jsonurl: function (t) {
        return Object.keys(t)
            .map(function (e) {
                return encodeURIComponent(e) + '=' + encodeURIComponent(t[e]);
            })
            .join('&');
    },
    json_remove: function (e, a) {
        if ('object' != t(e)) {
            e = (e = e.toString()).split(',');
        }
        var n = Array();
        for (var i in e) {
            if (e[i] != a) {
                n.push(e[i]);
            }
        }
        return n;
    },
    indexOf: function (e, a) {
        e = e.toString();
        a = a.toString();
        if ('object' != t(e)) {
            e = e.split(',');
        }
        return !(e.indexOf(a) < 0);
    },
    get_tabbar_index: function (t) {
        var a = app.globalData._ZEAI.tabbar.length;
        var n = 3;
        if (a > 0) {
            for (var i = 0; i < a; i++) {
                if (app.globalData._ZEAI.tabbar[i].var == t) {
                    n = i;
                }
            }
        }
        return n;
    }
};
